import { request } from '@umijs/max';
import { setAuthHeader } from '../utils/authInterceptor';

/**
 * 获取物资分类列表（分页）
 * @param params 查询参数
 * @returns 物资分类列表数据
 */
export async function getCategoryPaginated(params: any) {
  const headers: Record<string, string> = {
    'Content-Type': 'application/json',
  };
  
  // 添加认证头
  setAuthHeader(headers);
  
  return request('/api/category/list', {
    method: 'GET',
    params,
    headers,
  });
}

/**
 * 添加物资分类
 * @param data 分类数据
 * @returns 添加结果
 */
export async function addCategory(data: CATEGORY.CategoryModel) {
  const headers: Record<string, string> = {
    'Content-Type': 'application/json',
  };
  
  // 添加认证头
  setAuthHeader(headers);
  
  return request('/api/category/add', {
    method: 'POST',
    headers,
    data,
  });
}

/**
 * 更新物资分类
 * @param data 分类数据
 * @returns 更新结果
 */
export async function updateCategory(data: CATEGORY.CategoryModel) {
  const headers: Record<string, string> = {
    'Content-Type': 'application/json',
  };
  
  // 添加认证头
  setAuthHeader(headers);
  
  return request('/api/category/update', {
    method: 'PUT',
    headers,
    data,
  });
}

/**
 * 删除物资分类
 * @param id 分类ID
 * @returns 删除结果
 */
export async function removeCategory(id: number) {
  const headers: Record<string, string> = {
    'Content-Type': 'application/json',
  };
  
  // 添加认证头
  setAuthHeader(headers);
  
  return request(`/api/category/delete/${id}`, {
    method: 'DELETE',
    headers,
  });
}

/**
 * 获取物资分类详情
 * @param id 分类ID
 * @returns 分类详情
 */
export async function getCategoryDetail(id: number) {
  const headers: Record<string, string> = {
    'Content-Type': 'application/json',
  };
  
  // 添加认证头
  setAuthHeader(headers);
  
  return request(`/api/category/get/${id}`, {
    method: 'GET',
    headers,
  });
}